package test.socket

import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


/**
 * @author Eson
 */
class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val view = findViewById<View>(R.id.viewTest)
    view.setOnClickListener {
      ObjectAnimator.ofFloat(it, "translationX", 200f).setDuration(300).start()
    }
    val retrofit = Retrofit.Builder()
        .baseUrl("https://api.github.com/")
        .validateEagerly(true) // (测试时)一次性载入所有接口方法
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    val service = retrofit.create(GitHubService::class.java)
    val api = service.listRepos("ctroto")
    api.enqueue(object : Callback<List<RepoBean>>{
      override fun onFailure(call: Call<List<RepoBean>>, t: Throwable) {

      }

      override fun onResponse(call: Call<List<RepoBean>>, response: Response<List<RepoBean>>) {
        println(response.body()?.get(0)?.name)
      }
    })

  }
}